
package com.kanjian.music.adapter;

import java.util.ArrayList;

import com.kanjian.music.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SeekBar;

/**
 * 由于音乐分栏下需要像网易云音乐的效果(banner可下滑) 所以每个页面都设计成ListView MusicSubFragmentListAdapater
 * 为此种ListView的通用Adapter
 * 
 * @author xuyanjun@kanjian.com
 * @param <T> 每个页面的数据结构不同 这个参数就是每个页面展示数据所用到的实体类
 */
public class MusicSubFragmentListAdapater<T> extends BaseAdapter {

    protected final static int VIEW_TYPE_FAKE = 0;

    protected final static int VIEW_TYPE_DATA = 1;

    protected Context mContext;

    protected LayoutInflater mLayoutInflater;

    protected View mListFakeView;

    protected ArrayList<T> mDataList;

    public void setDataList(ArrayList<T> dataList) {
        this.mDataList = dataList;
        notifyDataSetChanged();
    }

    public MusicSubFragmentListAdapater(Context context) {
        this.mContext = context;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mDataList != null ? mDataList.size() + 1 : 0;
    }

    @Override
    public T getItem(int position) {
        if (position == 0) {
            return null;
        }
        return mDataList.get(position - 1);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (position == 0 && mListFakeView == null) {
            mListFakeView = mLayoutInflater.inflate(R.layout.view_music_sub_list_fake_view, parent,
                    false);
        }
        return null;
    }

}
